{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加宝箱</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                            <i class="fa fa-chevron-up"></i>
                        </a>
                        <a class="dropdown-toggle" data-toggle="dropdown" href="form_basic.html#">
                            <i class="fa fa-wrench"></i>
                        </a>
                        <a class="close-link">
                            <i class="fa fa-times"></i>
                        </a>
                    </div>
                </div>
                <div class="ibox-content">
                    <form class="form-horizontal" name="add_cate" id="add_box" method="post" action="">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="input-group col-sm-4">
                                <input id="name" type="text" class="form-control" name="name" value="{$data.name|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="controls uploadrow2" data-max="1" title="点击修改图片" rel="p_cover">
                                    <input type="hidden" name="logo" id="cover_id_p_cover" value="{$data.logo|default=''}" data-callback="uploadImgCallback" value=""/>
                                    <div class="upload-img-box" rel="img"  {if empty($data['logo'])} style="display:none" {/if} >
                                      <div class="upload-pre-item2">
                                            <img width="100" height="100" src="{$data.logo|default=''}"/>
                                      </div>
                                        <em class="edit_img_icon">&nbsp;</em>
                                    </div>
                              </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">说&nbsp;&nbsp;明：</label>
                            <div class="input-group col-sm-4">
                                <input type="text" class="form-control" name="remark" value="{$data.remark|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">奖励的道具类型：</label>
                            <div class="input-group col-sm-4" style="padding-top: 7px;">
                                {foreach name="prop_type" item="vo" key="k"} 
                                <input type="checkbox" class="i-checks" value="{$k}" name="reward_prop_type[]">{$vo}
                                {/foreach} 
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">物品数量：</label>
                            <div class="input-group col-sm-4">
                                <input  type="text" class="form-control" name="num" value="{$data.num|default=''}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排&nbsp;&nbsp;序：</label>
                            <div class="input-group col-sm-4">
                                <input id="orderby" type="text" class="form-control" name="orderby" value="{$data.orderby|default='50'}">
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状&nbsp;&nbsp;态：</label>
                            <div class="col-sm-6">
                                <div class="radio ">
                                    <input type="checkbox" name='status' value="{$data.status|default=1}" 
                                    class="js-switch" {if condition="@$data.status heq 0"}un{/if}checked />&nbsp;&nbsp;默认开启                                    
                                </div>
                            </div>
                        </div>
                        <input type="hidden" name='status' value="{$data.status|default=1}" >
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;&nbsp;
                                <a class="btn btn-danger" href="javascript:history.go(-1);"><i class="fa fa-close"></i> 返回</a>
                            </div>
                        </div>
                    </form>
                </div>
            </div>

        </div>
    </div>
</div>
{include file="public/footer" /}

<script type="text/javascript">

$(function(){
    
    //初始化上传图片插件
    initUploadImg();
});

function uploadImgCallback(name,id,src){

    $('#cover_id_p_cover').val(src);
}

//切换按钮
$('input[type="checkbox"][name=status]').change(function() {
    $('input[name=status]').val($(this).get(0).checked ? 1: 0);
});
</script>

<script type="text/javascript">

    $(function(){
        $('#add_box').ajaxForm({
            beforeSubmit: checkForm, 
            success: complete, 
            dataType: 'json'
        });
        
        function checkForm(){
            if( '' == $.trim($('#name').val())){
                layer.msg('请输入名称',{icon:2,time:1500,shade: 0.1}, function(index){
                layer.close(index);
                });
                return false;
            }
        }

        function complete(data){
            if(data.code==1){
                layer.msg(data.msg, {icon: 6,time:1500,shade: 0.1}, function(index){
                    window.location.href="{:url('box/index')}";
                });
            }else{
                layer.msg(data.msg, {icon: 5,time:1500,shade: 0.1});
                return false;   
            }
        }
     
    });

    //IOS开关样式配置
   var elem = document.querySelector('.js-switch');
        var switchery = new Switchery(elem, {
            color: '#1AB394'
        });
    var config = {
        '.chosen-select': {},                    
    }
    for (var selector in config) {
        $(selector).chosen(config[selector]);
    }

</script>
</body>
</html>